﻿#include <stdio.h>
#include <string.h>
void fun(char *s, char *c, int k)
{
    int i;
/**********found**********/
    for(i=0; s[i]!='\0'; i++)
    {
        if(s[i]>='a' && s[i]<='z')
            c[i]=(s[i]+k)>'z'?s[i]+k-26:s[i]+k;
	else if (s[i]>='A' && s[i]<='Z')
           c[i]=(s[i]+k)>'Z'?s[i]+k-26:s[i]+k;
/**********found**********/
        else c[i]=s[i];
    }
/**********found**********/
    c[i]= '\0';
}

void main()
{   char s[100]; /* 定义明文长度 */
    char c[100]; /* 定义密文长度 */
    int k;
    printf("Please input Secret Key:\n");
    scanf("%d", &k);getchar();
    printf("Please input Plaintext:\n");
    gets(s);
    fun(s,c,k);
    printf("The Ciphertext is : \n%s\n", c);
    getchar();
}
